package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.BatchlistBean;
import com.ukao.cashregister.bean.FactoryBatchBean;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.Utils;
import com.ukao.cashregister.view.SendFactoryView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by ukaodev on 2017/6/26.
 */

public class SendFactoryPesenter extends BasePresenter<SendFactoryView> {

    public SendFactoryPesenter(SendFactoryView view) {
        attachView(view);
    }





    public void batchInList(Context  mContext,int  pageNum,int pageSize) {
       // mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("pageNum",pageNum+"");
        mHashMap.put("pageSize",pageSize+"");
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.batchInList(Constant.createParameter(mHashMap)),
                new ApiCallback<BatchlistBean>() {
                    @Override
                    public void onSuccess(BatchlistBean model) {

                        if (model.getHttpCode() == 200) {

                            mvpView.loadSuccess(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }
                    }




                    @Override
                    public void onFinish() {
                    mvpView.finishLoad();
                    }
                });
    }

/*成批进厂   productIds*/
    public void batchInadd(Context   mContext ,String  productIds ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("orderProIds", productIds);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.batchInadd(Constant.createParameter(mHashMap)),
                new ApiCallback<FactoryBatchBean>() {
                    @Override
                    public void onSuccess(FactoryBatchBean model) {
                        if (model.getHttpCode() == 200) {

                            mvpView.batchEntrySuccess(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     衣物 添加
     */
    public void BatchInReladd( Context mContext, String id ,final String orderProIds ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("inId",id);
        mHashMap.put("orderProIds", orderProIds);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        Observable Observable;
        Observable =apiStores.BatchInReladd(Constant.createParameter(mHashMap)) ;
        addSubscription(Observable,
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.moveSuccess();

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }




    /**
     新建入厂袋号，并把能入厂衣物全部加入入厂袋号
     */
    public void buildBatchInReladd(  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        Observable Observable;
        Observable =apiStores.BuildaddAllBatchIn(Constant.createParameter(mHashMap)) ;
        addSubscription(Observable,
                new ApiCallback<FactoryBatchBean>() {
                    @Override
                    public void onSuccess(FactoryBatchBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.batchEntrySuccess(model.getData());

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**

     把能入厂衣物全部加入入厂袋号
     */
    public void addAllProductBatch( String  inId ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("inId",  inId);
        mHashMap.put("accessToken", SaveParamets.getToken(Utils.getContext()));
        Observable Observable;
        Observable =apiStores.addAllProductBatchInRel(Constant.createParameter(mHashMap)) ;
        addSubscription(Observable,
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {
                        if (model.getHttpCode() == 200) {
                            mvpView.moveSuccess();

                        }else{
                            mvpView.loadFail(model.getMsg());

                        }


                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }




}
